
rm(list=ls())
library(ctgt)
library(stringr)
library(xlsx)
load("gmincmax3.Rdata")
level = tc3$level
tmin= tc3$tmin
crt=tc3$crt
cmax = tc3$cmax
levs = tc3$levs
namebank = c("3", "13", "23", "34", "35","123", "134", "135", "234", "235", "345", "1234", "1235", "1345", "2345", "12345")
h3da_1 = as.data.frame(cbind(level,tmin,crt),col.names = c("level","tmin","crt"))
h3da_2 = as.data.frame( cbind(levs,cmax),col.names = c("levs","cmax"))
line_types <- c("l1" =1,"l2" =2)
point_types <- c("p1"=1, "p2"=2,"p3"=16,"p4" = 17)
library(ggplot2)
library(ggrepel)

jpeg("tmincmax3.jpg",width = 16, height = 10, units = 'cm', res = 600)

tc3 = ggplot(h3da_1, aes(level, tmin, shape = "p1")) + theme_classic() + xlim(level[1], level[16]+1) + ylim(0,tmin[16]+30 ) + 
  geom_point()  + 
  labs(title=expression(g[min]~and~c[max]~"for"~H["{3}"]), x="level", y = "test statistic & critical value") +
  theme(plot.title = element_text(hjust = 0.5, face="bold",size=16))+
  geom_text_repel(aes(level, tmin),label=namebank, nudge_y = 5,size= 3,segment.color = NA) +
  geom_point(aes(level, crt, shape = "p2")) +  
  geom_text_repel(aes(level, crt),label=namebank, nudge_y = -10,size= 3,segment.color = NA)+
  geom_line(aes(levs, cmax,linetype="l2"),data = h3da_2) + 
  geom_line(aes(level, tmin,linetype= "l1"), data = h3da_1[c(1,4,11,15,16),]) +
  geom_point(aes(level, tmin,shape = "p3"), data = h3da_1[c(1,4,11,15,16),]) +
  #geom_point(aes(level, crt,shape = "p4"), data = h3da_1[c(1,4,11,15,16),]) +
  #labs(shape="point type", linetype = "line type") +
  #scale_shape_manual(values=c(1,2), labels = c(expression(g[S]), expression(c[S])), name="point") +
  #scale_linetype_manual(values=c(1,2), labels = c(expression(g[min]), expression(c[max])), name="line") 
  scale_shape_manual(values=c(1,2,16,17), labels = c(expression(g[S]), expression(c[S]),
                                                     expression(g[B[R]^'F']),expression(c[B[R]^'F'])), name="point") +
  scale_linetype_manual(values=c(1,2), labels = c(expression(g[min]), expression(c[max])), name="line") +
  theme(legend.position = "none")
tc3
dev.off()

load("gmincmax2.Rdata")
level = tc2$level
tmin= tc2$tmin
crt=tc2$crt
cmax = tc2$cmax
levs = tc2$levs
namebank = c("2", "12", "23", "24", "25","123", "124", "125", "234", "235", "245", "1234", "1235", "1245", "2345", "12345")
h3da_1 = as.data.frame(cbind(level,tmin,crt),col.names = c("level","tmin","crt"))
h3da_2 = as.data.frame( cbind(levs,cmax),col.names = c("levs","cmax"))
line_types <- c("l1" =1,"l2" =2, "l3"=3)
point_types <- c("p1"=1, "p2"=2,"p3"=16,"p4" = 17)
library(ggplot2)

jpeg("tmincmax2.jpg",width = 16, height = 10, units = 'cm', res = 600)

tc2 = ggplot(h3da_1, aes(level, tmin, shape = "p1")) + theme_classic() + xlim(level[1], level[16]+1) + ylim(0,tmin[16]+30 ) + 
  geom_point()  + 
  labs(title=expression(g[min]~and~c[max]~"for"~H["{2}"]), x="level", y = "test statistic & critical value") +
  theme(plot.title = element_text(hjust = 0.5, face="bold",size=16))+
  geom_text_repel(aes(level, tmin),label=namebank, nudge_y = 5,size= 3,segment.color = NA) +
  geom_point(aes(level, crt, shape = "p2")) +  
  geom_text_repel(aes(level, crt),label=namebank, nudge_y = -10,size= 3,segment.color = NA)+
  geom_line(aes(levs, cmax,linetype="l2"),data = h3da_2) + 
  geom_line(aes(level, tmin,linetype= "l1"), data = h3da_1[c(1,4,11,14,16),]) +
  #geom_line(aes(level, crt,linetype= "l3"), data = h3da_1[c(1,4,11,14,16),]) +
  geom_point(aes(level, tmin,shape = "p3"), data = h3da_1[c(1,4,11,14,16),]) +
  geom_point(aes(level, crt,shape = "p4"), data = h3da_1[c(1,4,11,14,16),]) +
  #labs(shape="point type", linetype = "line type") +
  scale_shape_manual(values=c(1,2,16,17), labels = c(expression(g[S]), expression(c[S]),
                                                     expression(g[B[R]^'F']),expression(c[B[R]^'F'])), name="point") +
  scale_linetype_manual(values=c(1,2), labels = c(expression(g[min]), expression(c[max])), name="line")

tc2
dev.off()



load("gmincmax1.Rdata")
level = tc1$level
tmin= tc1$tmin
crt=tc1$crt
cmax = tc1$cmax
levs = tc1$levs
namebank = c("1", "12", "13", "14", "15","123", "124", "125", "134", "135", "145", "1234", "1235", "1245", "1345", "12345")
h3da_1 = as.data.frame(cbind(level,tmin,crt),col.names = c("level","tmin","crt"))
h3da_2 = as.data.frame( cbind(levs,cmax),col.names = c("levs","cmax"))
line_types <- c("l1" =1,"l2" =2, "l3"=3)
point_types <- c("p1"=1, "p2"=2,"p3"=16,"p4" = 17)
library(ggplot2)

jpeg("tmincmax1.jpg",width = 16, height = 10, units = 'cm', res = 600)

tc1 = ggplot(h3da_1, aes(level, tmin, shape = "p1")) + theme_classic() + xlim(level[1], level[16]+1) + ylim(0,tmin[16]+30 ) + 
  geom_point()  + 
  labs(title=expression(g[min]~and~c[max]~"for"~H["{1}"]), x="level", y = "test statistic & critical value") +
  theme(plot.title = element_text(hjust = 0.5, face="bold",size=16))+
  geom_text_repel(aes(level, tmin),label=namebank, nudge_y = 5,size= 3,segment.color = NA) +
  geom_point(aes(level, crt, shape = "p2")) +  
  geom_text_repel(aes(level, crt),label=namebank, nudge_y = -10,size= 3,segment.color = NA)+  
  #geom_text(aes(level, crt),label=namebank,vjust = -0.5, nudge_y = -39,size= 3)+
  geom_line(aes(levs, cmax,linetype="l2"),data = h3da_2) + 
  geom_line(aes(level, tmin,linetype= "l1"), data = h3da_1[c(1,4,11,14,16),]) +
  #geom_line(aes(level, crt,linetype= "l3"), data = h3da_1[c(1,4,11,14,16),]) +
  geom_point(aes(level, tmin,shape = "p3"), data = h3da_1[c(1,4,11,14,16),]) +
  geom_point(aes(level, crt,shape = "p4"), data = h3da_1[c(1,4,11,14,16),]) +
  #labs(shape="point type", linetype = "line type") +
  scale_shape_manual(values=c(1,2,16,17), labels = c(expression(g[S]), expression(c[S]),
                                                     expression(g[B[R]^'F']),expression(c[B[R]^'F'])), name="point") +
  scale_linetype_manual(values=c(1,2), labels = c(expression(g[min]), expression(c[max])), name="line")

tc1
dev.off()

library(ggpubr)
tiff("tc123.tiff",width = 16, height = 26, units = 'cm', res = 600)
#jpeg("tc123.jpg",width = 16, height = 26, units = 'cm', res = 600)
ggarrange(tc3,                                                 # First row with scatter plot
          ggarrange(tc2, tc1, ncol = 1, nrow = 2, labels = c("B", "C"), legend = "bottom", common.legend = TRUE), # Second row with box and dot plots
          nrow = 2,
          labels = "A",
          heights = c(1, 2) # Labels of the scatter plot
)

dev.off()


